<template>
  <div class="wrapper">
    <!-- header部分 -->
    <header>
      <p>发现</p>
    </header>

    <div class="carousel">
      <div @click="prevSlide" class="carousel-prev-icon-left"></div>
      <div class="carousel-slides">
        <img
          v-for="(image, index) in images"
          :key="index"
          :src="image"
          :style="{ left: index * 100 + '%', transform: dynamicstyle }"
          alt="暂无图片"
        />
      </div>
      <div @click="nextSlide" class="carousel-prev-icon-right"></div>
    </div>

    <div class="function-options">
        <div class="option">
          <img src="../assets/特色.png" />
          <div @click="toFoodIntroduction">特色美食介绍</div>
        </div>
      </div>
      <div class="function-options">
        <div class="option">
          <img src="../assets/菜谱.png" />
          <div @click="toDietRecipe">减脂菜谱推荐</div>
        </div>
      </div>
      <div class="function-options">
        <div class="option">
          <img src="../assets/店铺.png" />
          <div @click="toRankList" >店铺排行榜</div>
        </div>
      </div>
        <div class="function-options">
        <div class="option">
         <img src="../assets/美食.png"  />
          <div @click="toFoodLevel" >美食排行榜</div>
        </div>
        </div>
    </div>

 

</template>

<script>

export default {
  name: "Search",
  data() {
    return {
      images: [
        "https://glutljy.oss-cn-guangzhou.aliyuncs.com/%E7%89%B9%E8%89%B2%E7%BE%8E%E9%A3%9F%E5%9B%BE%E7%89%87/1.webp",
        "https://glutljy.oss-cn-guangzhou.aliyuncs.com/%E7%89%B9%E8%89%B2%E7%BE%8E%E9%A3%9F%E5%9B%BE%E7%89%87/10.webp",
        "https://glutljy.oss-cn-guangzhou.aliyuncs.com/%E7%89%B9%E8%89%B2%E7%BE%8E%E9%A3%9F%E5%9B%BE%E7%89%87/16.webp",
      "https://glutljy.oss-cn-guangzhou.aliyuncs.com/%E7%89%B9%E8%89%B2%E7%BE%8E%E9%A3%9F%E5%9B%BE%E7%89%87/17.webp",
      "https://glutljy.oss-cn-guangzhou.aliyuncs.com/%E7%89%B9%E8%89%B2%E7%BE%8E%E9%A3%9F%E5%9B%BE%E7%89%87/20.webp",
      "https://glutljy.oss-cn-guangzhou.aliyuncs.com/%E7%89%B9%E8%89%B2%E7%BE%8E%E9%A3%9F%E5%9B%BE%E7%89%87/21.webp",
      "https://glutljy.oss-cn-guangzhou.aliyuncs.com/%E7%89%B9%E8%89%B2%E7%BE%8E%E9%A3%9F%E5%9B%BE%E7%89%87/25.webp",
      "https://glutljy.oss-cn-guangzhou.aliyuncs.com/%E7%89%B9%E8%89%B2%E7%BE%8E%E9%A3%9F%E5%9B%BE%E7%89%87/28.webp",
      "https://glutljy.oss-cn-guangzhou.aliyuncs.com/%E7%89%B9%E8%89%B2%E7%BE%8E%E9%A3%9F%E5%9B%BE%E7%89%87/34.webp"
      ],
      dynamicstyle: "",
      currentSlide: 0,
      interval: Object,
      selectedCategory: "",
      merchants: []
      
    };
  },
  mounted() {
    // 自动播放动画
    this.startSlideshow();
     
  },
  methods: {
    nextSlide() {
      this.currentSlide = (this.currentSlide + 1) % this.images.length;
      this.setStyle();
    },
    prevSlide() {
      this.currentSlide = (this.currentSlide - 1 + this.images.length) % this.images.length;
      this.setStyle();
    },
    setStyle() {
      this.dynamicstyle = `translateX(-${this.currentSlide * 100}%)`;
    },
    startSlideshow() {
      this.interval = setInterval(() => {
        this.currentSlide = (this.currentSlide + 1) % this.images.length;
        this.setStyle();
      }, 3000);
    },
    stopSlideshow() {
      clearInterval(this.interval);
    },
    
 toRankList() {
      // 使用this.$router.push进行编程式路由跳转
      this.$router.push('/rankList');
    },
    toFoodLevel() {
      // 使用this.$router.push进行编程式路由跳转
      this.$router.push('/foodLevel');
    },
    toFoodIntroduction()
    {
      this.$router.push('/foodIntroduction');
    },
    toDietRecipe(){
      this.$router.push('/dietRecipe');
    }
  }
};

</script>
<style>
/****************** 总容器 ******************/
.wrapper {
  width: 100%;
  height: 100%;
}

/****************** header部分 ******************/
.wrapper header {
  width: 100%;
  height: 12vw;
  background-color: #0097ff;
  color: #fff;
  font-size: 4.8vw;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
}

/****************** 轮播图部分 ******************/
.carousel {
  margin-top: 12vw;
  position: relative;
}

.carousel-slides {
  position: relative;
  width: 375px;
  height: 200px;
  overflow: hidden;
}

.carousel-slides img {
  display: inline-block;
  position: absolute;
  width: inherit;
  padding: 0;
  top: 0;
  left: 0;
  height: 100%;
  transition: 0.5s transform ease-in-out;
}

.carousel-prev-icon-left, .carousel-prev-icon-right {
  position: absolute;
  height: 50px;
  width: 40px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  z-index: 1000;
}

.carousel-prev-icon-left {
  left: 10px;
  top: 55px;
  background-image: url('../../../assets/img/arrow-l.png');
}

.carousel-prev-icon-right {
  right: 10px;
  top: 55px;
  background-image: url('../../../assets/img/arrow-r.png');
}

/****************** title部分 ******************/
.title {
  margin-left: 0;
  height: 40px;
  width: 355px;
  background-color: #fff;
  border-bottom: 1px solid #DCDCDC;
  display: flex;
  padding: 0 10px;
}

span {
  font-size: 12.5px;
  cursor: pointer;
  padding: 10px 15px;
  transition: all 0.3s ease;
  border-radius: 7px;
  text-align: center;
}

span:hover {
  background-color: #f0f0f0;
  transform: scale(1.1);
}

span.active {
  background-color: #0097ff;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/****************** 内容部分 ******************/
.content {
  padding: 20px;
}

.merchant {
  margin-bottom: 10px;
  padding: 10px;
  border: 1px solid #DCDCDC;
  border-radius: 4px;
  background-color: #f9f9f9;
}
/* 功能选项容器样式 */
.function-options {
  display: flex; /* 使用Flexbox布局 */
  justify-content: space-between; /* 子元素之间的间隔均匀分布 */
  align-items: center; /* 垂直居中 */
  padding: 10px; /* 内边距 */
  background-color: #fff; /* 背景颜色 */
  border: 1px solid #DCDCDC; /* 边框 */
  border-radius: 4px; /* 边框圆角 */
}

/* 单个选项样式 */
.option {
  display: flex; /* 使用Flexbox布局 */
  align-items: center; /* 垂直居中 */
  text-decoration: none; /* 去除下划线 */
  color: inherit; /* 颜色继承 */
  transition: all 0.3s ease; /* 平滑过渡效果 */
}

/* 选项中的图片样式 */
.option img {
  width: 50px; /* 图片宽度 */
  height: 50px; /* 图片高度 */
  margin-right: 10px; /* 图片右侧的外边距 */
}

/* 选项中的router-link样式 */
.option router-link {
  font-size: 14px; /* 字体大小 */
  padding: 10px; /* 内边距 */
  border-radius: 7px; /* 边框圆角 */
  text-align: center; /* 文本居中 */
  cursor: pointer; /* 鼠标指针样式 */
}

/* router-link悬停样式 */
.option router-link:hover {
  background-color: #f0f0f0; /* 悬停时的背景颜色 */
  transform: scale(1.1); /* 悬停时的缩放效果 */
}

/* router-link激活样式 */
.option router-link.active {
  background-color: #0097ff; /* 激活时的背景颜色 */
  color: #fff; /* 文本颜色 */
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); /* 阴影效果 */
}
</style>0